﻿package view.prompt
{
    import flash.display.*;
    import flash.events.*;
    import morn.core.components.*;
    import morn.core.handlers.*;

    public class ButtonPromptCell extends Sprite implements IPrompt
    {
        protected var btn:Button;
        private var _changeHandler:Handler;
        public var _btnMsg:Object;

        public function ButtonPromptCell()
        {
            return;
        }// end function

        public function createCell(param1:Sprite, param2:Object, param3:Handler) : void
        {
            param1.addChild(this);
            this.visible = false;
            this._btnMsg = param2;
            this._changeHandler = param3;
            this.btn = new Button(PromptProtocol.sourcePath + param2.name);
            this.addChild(this.btn);
            this.initEvent();
            return;
        }// end function

        public function show(param1:Object) : void
        {
            this.visible = true;
            if (this._changeHandler)
            {
                this._changeHandler.execute();
            }
            return;
        }// end function

        public function hide() : void
        {
            this.visible = false;
            if (this._changeHandler)
            {
                this._changeHandler.execute();
            }
            return;
        }// end function

        public function initEvent() : void
        {
            this.btn.clickHandler = new Handler(this.doMouse, [null]);
            return;
        }// end function

        protected function doMouse(event:MouseEvent) : void
        {
            this.visible = false;
            if (this._changeHandler != null)
            {
                this._changeHandler.execute();
            }
            return;
        }// end function

        public function removeEvent() : void
        {
            return;
        }// end function

        public function destroy() : void
        {
            if (this.btn)
            {
                this.removeEvent();
                if (this.btn.parent)
                {
                    this.btn.parent.removeChild(this.btn);
                }
                this.btn = null;
            }
            if (this.parent)
            {
                this.parent.removeChild(this);
            }
            this._changeHandler = null;
            return;
        }// end function

    }
}
